package com.ruoyi.web.hvisionsController;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.web.domain.HvHome;
import com.ruoyi.web.service.IHvHomeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 首页Controller
 *
 * @author ruoyi
 * @date 2023-11-09
 */
@Api(tags="首页管理")
@RestController
@RequestMapping("/hv/home")
public class HvHomeController extends BaseController
{
    @Autowired
    private IHvHomeService hvHomeService;

    /**
     * 查询首页列表
     */
    @ApiOperation("查询首页列表")
    @PreAuthorize("@ss.hasPermi('system:home:list')")
    @GetMapping("/list")
    public TableDataInfo list(HvHome hvHome)
    {
        startPage();
        List<HvHome> list = hvHomeService.selectHvHomeList(hvHome);
        return getDataTable(list);
    }

    /**
     * 导出首页列表
     */
    @ApiOperation("导出首页列表")
    @PreAuthorize("@ss.hasPermi('system:home:export')")
    @Log(title = "首页", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HvHome hvHome)
    {
        List<HvHome> list = hvHomeService.selectHvHomeList(hvHome);
        ExcelUtil<HvHome> util = new ExcelUtil<HvHome>(HvHome.class);
        util.exportExcel(response, list, "首页数据");
    }

    /**
     * 获取首页详细信息
     */
    @ApiOperation("获取首页详细信息")
    @PreAuthorize("@ss.hasPermi('system:home:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hvHomeService.getById(id));
    }

    /**
     * 新增首页
     */
    @ApiOperation("新增首页")
    @PreAuthorize("@ss.hasPermi('system:home:add')")
    @Log(title = "首页", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HvHome hvHome)
    {
        return toAjax(hvHomeService.save(hvHome));
    }

    /**
     * 修改首页
     */
    @ApiOperation("修改首页")
    @PreAuthorize("@ss.hasPermi('system:home:edit')")
    @Log(title = "首页", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HvHome hvHome)
    {
        return toAjax(hvHomeService.updateById(hvHome));
    }

    /**
     * 删除首页
     */
    @ApiOperation("删除首页")
    @PreAuthorize("@ss.hasPermi('system:home:remove')")
    @Log(title = "首页", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hvHomeService.removeByIds(Arrays.asList(ids)));
    }
}
